#!/bin/sh
MAKE="gmake"
export MAKE
HDD_IMAGE="hdd.img"
KRNL_IMAGE="kernel"
KRNL_ZIP="kernel.gz"
MYOS_SRC=`pwd`"/src"
OS_PATH=`pwd`
export MYOS_SRC

echo "Compiling MyOs...in "${MYOS_SRC}
cd src
${MAKE} $1
cd ../
echo "Ok."

if [ $1 ]; then
    exit 1
fi

echo "Configuring image..."
MDEVICE=`mdconfig -a -t vnode -f ${OS_PATH}"/img/"${HDD_IMAGE}`
echo -n "Mounting HDD image..."
mount -t msdosfs "/dev/"${MDEVICE}"s1" ${OS_PATH}/hdd
echo "Ok."

echo "Copying OS..."
# mkdir ${OS_PATH}/hdd/sys
rm -f ${MYOS_SRC}/"sys/"${KRNL_ZIP}
gzip ${MYOS_SRC}"/sys/"${KRNL_IMAGE}
cp -f ${MYOS_SRC}"/sys/"${KRNL_ZIP} ${OS_PATH}"/hdd/sys/"${KRNL_ZIP}
umount ${OS_PATH}/hdd
mdconfig -d -u ${MDEVICE}

echo "Done."
unset $MYOS_SRC
unset $MAKE
exit 0


